import req from '@/utils/request'

import type {
  MenuDataType,
  AddMenuParamsType,
  UpdateMenuParamsType,
} from './model/menuType'

enum Api {
  getMenuByRole = '/admin/acl/permission/toAssign',
  doAssign = '/admin/acl/permission/doAssign',
  getMenu = '/admin/acl/permission',
  addMenu = '/admin/acl/permission/save',
  updateMenu = '/admin/acl/permission/update',
  removeMenu = '/admin/acl/permission/remove',
}

// 根据角色获取菜单数据
export const getMenuByRoleApi = (roleId: string) => {
  return req.get<null, MenuDataType>(`${Api.getMenuByRole}/${roleId}`)
}

// 给角色分配权限
export const doAssignApi = (roleId: string, idList: string[]) => {
  return req.post<null, null>(
    `${Api.doAssign}?roleId=${roleId}&permissionId=${idList}`
  )
}

// 获取菜单
export const getMenuApi = () => {
  return req.get<null, MenuDataType>(Api.getMenu)
}

// 添加菜单
export const addMenuApi = (params: AddMenuParamsType) => {
  return req.post<null, null>(Api.addMenu, params)
}

// 修改菜单
export const updateMenuApi = (params: UpdateMenuParamsType) => {
  return req.put<null, null>(Api.updateMenu, params)
}

// 删除菜单
export const removeMenuApi = (id: string) => {
  return req.delete<null, null>(`${Api.removeMenu}/${id}`)
}
